package com.uikoo9.manage.y.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.uikoo9.util.core.annotation.QTable;
import com.uikoo9.util.core.data.QStringUtil;

/**
 * YQuotesModel<br>
 * id	id<br>
 * cuser_id	创建者<br>
 * cuser_name	创建<br>
 * cdate	创建时间<br>
 * y_topic_name	标题<br>
 * y_topic_content	内容<br>
 * @author qiaowenbin
 */
@QTable("t_y_quotes")
@SuppressWarnings("serial")
public class YQuotesModel extends Model<YQuotesModel>{
	
	public static final YQuotesModel dao = new YQuotesModel();
	
	/**
	 * find all
	 * @return
	 */
	public List<YQuotesModel> findAll(){
		return findAll(null);
	}

	public Record getNextQuotes(Integer id){
		String _sql = "select * from t_y_quotes where id >? order by id";
		Record record = Db.findFirst(_sql,id);
		if(record ==null){
			record = Db.findFirst(_sql,0);
		}
		return record;
	}

	/**
	 * find all by order
	 * @param order
	 * @return
	 */
	public List<YQuotesModel> findAll(String order){
		StringBuilder sb = new StringBuilder("select * from t_y_quotes ");
		if(QStringUtil.isEmpty(order)){
			return dao.find(sb.append("order by id desc").toString());
		}else{
			return dao.find(sb.append(order).toString());
		}
	}
	
}
